package com.yunfeng.web.util;

import java.util.ArrayList;

public class ResultGenerator<T> {
    private final String DEFAULT_SUCCESS_MESSAGE = "成功";
    private final String DEFAULT_FAIL_MESSAGE = "数据信息获取失败";
    private Result<T> result;

    public ResultGenerator() {
        result = new Result<>();
    }

    public Result<T> getSuccessResult() {
        result.setReturnCode(Constants.RESULT_CODE_SUCCESS);
        result.setReturnMemo(DEFAULT_SUCCESS_MESSAGE);
        return result;
    }

    public Result<T> getSuccessResultWithMemo(String ReturnMemo){
        result.setReturnCode(Constants.RESULT_CODE_SUCCESS);
        result.setReturnMemo(ReturnMemo);
        return result;
    }

    public Result<T> getSuccessResultWithMemo(int Code, String ReturnMemo){
        result.setReturnCode(Code);
        result.setReturnMemo(ReturnMemo);
        return result;
    }
//    @SuppressWarnings({ "rawtypes", "unchecked" })
//	public static Result genSuccessResult(Object data) {
//        Result result = new Result();
//        result.setReturnCode(Constants.RESULT_CODE_SUCCESS);
//        result.setReturnMemo(DEFAULT_SUCCESS_MESSAGE);
//        result.setData(data);
//        return result;
//    }

    public Result<T> getFailResult(String ReturnMemo) {
        result.setData(new ArrayList<>());
        result.setReturnCode(Constants.RESULT_CODE_SERVER_ERROR);
        if (ReturnMemo == null || ReturnMemo.length() < 1) {
            ReturnMemo = DEFAULT_FAIL_MESSAGE;
        }
        result.setReturnMemo(ReturnMemo);
        return result;
    }

}